package com.cn.jinl.controller;


import com.cn.jinl.api.IOnDutyBgTaskService;
import com.cn.jinl.domain.OnDutyBgTask;
import com.cn.jinl.domain.OnDutyBgTaskDetailVo;
import com.cn.jinl.domain.OnDutyBgTaskUser;
import com.cn.jinl.domain.OnDutyBgTaskVo;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/bgTask")
public class OnDutyBgTaskController {

    @Autowired
    private IOnDutyBgTaskService onDutyBgTaskService;

    @ResponseBody
    @RequestMapping("/getOnDutyBgTaskList/{frontToken}")
    public JsonResponse<Map<String,Object>> getOnDutyBgTaskList(@RequestParam("bgId") String bgId, @RequestParam("whiteDay") String whiteDay, @PathVariable(value = "frontToken", required = true) String frontToken) throws Exception {
        JsonResponse<Map<String,Object>> response = new JsonResponse<Map<String,Object>>();
        Map<String,Object> result = onDutyBgTaskService.getOnDutyBgTaskList(bgId,whiteDay);
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/getOnDutyBgTaskListByItemName/{frontToken}")
    public JsonResponse<List<OnDutyBgTask>> getOnDutyBgTaskListByItemName(QueryForm queryForm, @PathVariable(value = "frontToken", required = true) String frontToken) throws Exception {
        JsonResponse<List<OnDutyBgTask>> response = new JsonResponse<List<OnDutyBgTask>>();
        List<OnDutyBgTask> result = onDutyBgTaskService.getOnDutyBgTaskListByItemName(queryForm);
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/getAllBgTasksByBgId/{frontToken}")
    public JsonResponse<List<OnDutyBgTaskDetailVo>> getAllBgTasksByBgId(String bgId, @PathVariable(value = "frontToken", required = true) String frontToken) throws Exception {
        JsonResponse<List<OnDutyBgTaskDetailVo>> response = new JsonResponse<List<OnDutyBgTaskDetailVo>>();
        List<OnDutyBgTaskDetailVo> result = onDutyBgTaskService.getAllBgTasksByBgId(bgId);
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/getOnDutyBgTaskUsersByTaskId/{frontToken}")
    public JsonResponse<List<OnDutyBgTaskUser>> getOnDutyBgTaskUsersByTaskId(String taskId, @PathVariable(value = "frontToken", required = true) String frontToken) throws Exception {
        JsonResponse<List<OnDutyBgTaskUser>> response = new JsonResponse<List<OnDutyBgTaskUser>>();
        List<OnDutyBgTaskUser> result = onDutyBgTaskService.getOnDutyBgTaskUsersByTaskId(taskId);
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/getOnDutyBgTaskWithUserListById/{frontToken}")
    public JsonResponse<OnDutyBgTask> getOnDutyBgTaskWithUserListById(String id, @PathVariable(value = "frontToken", required = true) String frontToken) throws Exception {
        JsonResponse<OnDutyBgTask> response = new JsonResponse<OnDutyBgTask>();
        OnDutyBgTask result = onDutyBgTaskService.getOnDutyBgTaskWithUserListById(id);
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }


    @RequestMapping("/batchUpdateOnDutyBgTasks/{frontToken}")
    @ResponseBody
    public JsonResponse<String> batchUpdateOnDutyBgTasks(@RequestBody OnDutyBgTaskVo onDutyBgTaskVo, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = onDutyBgTaskService.batchUpdateOnDutyBgTasks(onDutyBgTaskVo);
        return CommonUtil.getResponseData(response,result);
    }
}
